<template>
    <div>
        <div style="margin-top: 15px;display: flex;justify-content: space-between;">
            <el-form :inline="true" :model="forObject" class="demo-form-inline" >
                <el-form-item>
                    <el-input v-model="forObject.name" placeholder="博客名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-input v-model="forObject.authorName" placeholder="作者名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" @click="page">查询</el-button>
                    <el-button type="primary" icon="el-icon-bottom">高级搜索</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div>
            <ElementTable ref="pageTable"
                          :pageColumns="pageColumns"
                          :optBtn="optBtn"
                          :btnList="btnList"
                          :optWidth=150
                          :url="url"
                          :formObject="forObject"
                          :loading="loading"
                          @optClick="optClick"
                          @btnListClick="btnListClick"
            >

            </ElementTable>
        </div>

        <NewsListEdit ref="refNewsListEdit" @page="page"></NewsListEdit>
    </div>

</template>

<script>
    import ElementTable from '../../../components/base/ElementTable'
    import NewsListEdit from './BlogAdviseEdit'
    import {postReq} from "../../../utils/api";
    export default {
        name: "RecommendList",
        components:{
            ElementTable,
            NewsListEdit
        },
        mounted() {
            this.page()
        },
        data(){
            return{
                selectIds:[],
                forObject:{
                    name:undefined,
                    authorName:undefined
                },
                url:'/api/blog/page',
                loading:true,
                pageColumns:[
                    {key:'title',title:'博客标题',width:200},
                    {key:'onShelf',title:'是否推荐',width:100},
                    {key:'name',title:'内容',width:200},
                    {key:'authorName',title:'作者',width:200},
                    {key:'browseQuantity',title:'浏览量',width:200},
                    {key:'praiseQuantity',title:'点赞量',width:160},
                    {key:'commentQuantity',title:'评论量',width:200},

                    {key:'releaseTime',title:'发布时间',width:200}
                ],
                optBtn:[
                    {icon:'el-icon-edit',name:'推荐',id:''}
                ],
                btnList:[
                    {icon:'el-icon-plus',type:'success',name:'添加',id:''},
                    {icon:'el-icon-plus',type:'success',name:'导入',id:''},
                    {icon:'el-icon-plus',type:'primary',name:'导出',id:''}
                ],
                getPage: {},
            }
        },
        methods:{
            btnListClick(name){
                switch (name) {
                    case '添加':
                        this.edit()
                        break
                }
            },
            optClick(data){
               switch (data.name) {
                   case '推荐':
                       this.recommend(data.obj)
                       break
                   case '图片上传':
                       this.imgUpload(data.obj)
                       break
                   case 'selectData':
                       let ids = []
                       if (data.obj.length==0){
                           this.selectIds=[]
                       }else {
                           data.obj.forEach(function (item,value) {
                               ids[value]=item.id
                           })
                       }
                       this.selectIds = ids
                       break
               }
            },
            page(){
                this.$refs.pageTable.page()
            },
            addCompany(){
                this.$refs.refSysCompanyEdit.open()
            },
            edit(obj){
                this.$refs.refNewsListEdit.open(obj)
            },
            imgUpload(obj){
                this.$refs.refNewsImgUpload._open(obj.id)
            },
            recommend(obj){
                if (obj.onShelf===undefined||obj.onShelf===0||obj.onShelf==='0'){
                    postReq('/api/blog/recommend?id='+obj.id).then(res=>{
                        this.page()
                    })
                }else{
                    postReq('/api/blog/recommend_not?id='+obj.id).then(res=>{
                        this.page()
                    })
                }

            }

        }
    }
</script>

<style scoped>

</style>